|
|
|
|
|
|
|
Kill strMake
Else
ErrMsg 0, "Script Cancel - database already Exists", intLine, strLine,
"SQLdbMake"
InitApp
End If
'
' now try to make a new database
SQLdbMake2:
' create a new db, close it, then open for use
Set ws = DBEngine.CreateWorkspace("wsSQLVB2", "admin", "")
Set db = ws.CreateDatabase(strMake, dbLangGeneral, strVersion)
db.Close
Set db = ws.OpenDatabase(strMake, False, False, strConnect)
strGlobalDBName = strMake
intDBFlag = True
GoTo SQLdbMakeExit
'
SQLdbMakeErr:
If Err = 53 Then
Resume SQLdbMake2
Else
ErrMsg Err, Error$, intLine, strLine, "SQLdbMake"
InitApp
End If
'
SQLdbMakeExit:
'
End Sub |
|
|
|
|
|
|
|
|
A few things in this routine deserve attention. First, the routine drops the first word from the script line (the DBMAKE word). Then it strips the semicolon off the end of the line, if necessary. Then, instead of performing the create operation, the routine first tries to open the file. This is done to see if it already exists. If it does, you can issue a warning before you clobber that multimegabyte database that the user has been nursing for the last few months. If no error occurs when you try to open the file, the routine sends out a message warning the user and asking if it's okay to erase the existing file. If the answer is Yes, the file is erased. If the answer is No, a message is displayed, and script processing is halted. |
|
|
|
|
|
|
|
|
Now, if an error occurs during the attempt to open the file, you know that the file does not exist. The local error handler is invoked and the first thing it checks is whether the error was caused by an attempt to open a nonexistent file. If so, the error handler sends the routine to the file creation point without comment. If the error has another cause, the global error handler is called and the program is halted. |
|
|
|
|
|
|
|
|
Finally, after all the file creation stuff is sorted out, the routine executes the Visual Basic CreateDatabase operation and returns to the SQLFileProcess routine. Notice that you declared two parameters during the CreateDatabase operation. The first parameter (vbLangGeneral) tells Visual Basic to use the general rules for sorting and collating data. The second parameter (strVersion) can be set by the user with the DBVERSION keyword. |
|
|
|
|
|